/*
 *The code is written by NaLi, All rights reserved.
 */
package com.nali.dal.statement.function.formatter.date;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.nali.dal.statement.function.DoubleArgumentDataHandler;
import com.nali.dal.statement.function.FunctionException;

/**
 * @author gavin 
 * Created on 2011-4-9
 */
@Component
public class Truncate extends DoubleArgumentDataHandler<Object, Date>{

	@Override
	protected Date handle(Object arg1, Object arg2) throws FunctionException {
		String timeUnitStr = (String) arg2;
		Date date = (Date) arg1;
		TimeUnit timeUnit = TimeUnit.getTimeUnit(timeUnitStr);
		return timeUnit.convert(date);
	}
}

